<template>
  <div>
    <div class="head">
      <van-icon class="arrow-left" name="arrow-left" @click="goBack" />
      <p>注册</p>
    </div>
    <van-empty description="请设置登录密码" />
    <van-cell-group>
      <van-field
        v-model="value"
        :type="type"
        clearable
        :right-icon="typeIcon"
        @click-right-icon="changeIocn(typeIcon)"
        @input="changeLength"
        placeholder="请设置至少六位登陆密码"
      />
    </van-cell-group>
    <p>密码强度校验,最少6位,包括至少1个大写字母,1个小写字母,1个数字</p>
    <van-button
      size="large"
      color="red"
      round
      :disabled="disabled"
      clearable
      type="primary"
      @click="goReg"
      >完成</van-button
    >
  </div>
</template>

<script>
export default {
  name: "Regpass",
  data() {
    return {
      tel: "",
      type: "password",
      value: "",
      typeIcon: "closed-eye",
      disabled: true,
    };
  },
  created() {
    console.log(this.$route.query.tel);
    this.tel = this.$route.query.tel;
  },
  methods: {
    goBack() {
      this.$router.back();
    },
    changeIocn(val) {
      if (val == "closed-eye") {
        this.type = "text";
        this.typeIcon = "eye-o";
      } else {
        this.type = "password";
        this.typeIcon = "closed-eye";
      }
    },
    changeLength() {
      var reg = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$/;
      if (reg.test(this.value)) {
        this.disabled = false;
      } else {
        this.disabled = true;
      }
    },
    goReg() {
      this.$server({
        url: "/api/user/dofinishregister",
        method: "post",
        data: {
          tel: this.tel,
          password: this.value,
        },
      }).then((res) => {
        if (res.data.code == 200) {
          console.log(res);
          this.$router.push("/Login");
        }
      });
    },
  },
};
</script>

<style scoped>
.head {
  height: 45px;
  background-color: antiquewhite;
  text-align: center;
  line-height: 45px;
}
.arrow-left {
  float: left;
  margin: 1rem;
  color: blue;
}
p {
  text-align: center;
  margin-right: 42px;
}
button {
  width: 20rem;
  height: 2.5rem;
  background: red;
  color: white;
  border: none;
  border-radius: 25px;
  margin-left: 1.2rem;
  margin-top: 1.5rem;
}
</style>
